package service.impl;


import bean.ClassBean;
import mapper.IClassMapper;
import service.IClassService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ClassServiceImpl extends BaseService implements IClassService {
    @Override
    public List<ClassBean> listClass() {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        List<ClassBean> list = mapper.listClass();
        session.close();
        return list;
    }

    @Override
    public void insert(ClassBean classBean) {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        mapper.insert(classBean);
        session.commit();
        session.close();
    }

    @Override
    public boolean delete(Integer id) {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        int count = mapper.findStudentCount(id);
        if (count == 0) {
            mapper.delete(id);
            session.commit();
            session.close();
            return true;
        } else {
            return false;
        }
    }
}
